<html>
<head><meta charset="utf-8"><title>Internment memory limit · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Internment.20memory.20limit.html">Internment memory limit</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204976812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Internment%20memory%20limit/near/204976812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chase Wilson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Internment.20memory.20limit.html#204976812">(Jul 24 2020 at 23:37)</a>:</h4>
<p>I thought here would be a much easier method of communicating than over github issues, it just makes things faster</p>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> In regards to the <code>lasso</code> crate, would a hard cap on the memory used by string internment be something you'd be interested in? If so, how accurate of one would you like, since there's varying levels of accuracy that it can reach (trading implementation time and speed of course)</p>
<ol>
<li>Only track the currently allocated arena memory (Least accurate, still gets the vast majority of memory tracked)</li>
<li>Track as much memory as possible by recording <code>(size_of::&lt;Key&gt;() * self.map.len() * 2) + (size_of::&lt;&amp;str&gt;() * self.map().len() * 2) + memory_in_arena</code> (About as close as it's possible to get to being perfectly accurate, does involve much more complexity though)</li>
</ol>



<a name="204976892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Internment%20memory%20limit/near/204976892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Internment.20memory.20limit.html#204976892">(Jul 24 2020 at 23:39)</a>:</h4>
<p>I'm not sure, what would happen if the limit is reached?</p>



<a name="204978959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Internment%20memory%20limit/near/204978959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Internment.20memory.20limit.html#204978959">(Jul 25 2020 at 00:21)</a>:</h4>
<p>(we wouldn't really need a terribly good accuracy here fwiw)</p>



<a name="205023759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Internment%20memory%20limit/near/205023759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chase Wilson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Internment.20memory.20limit.html#205023759">(Jul 25 2020 at 22:10)</a>:</h4>
<p>Well, it'd either make the <code>.get_or_intern</code> call return a <code>None</code> or it'd change all the functions that currently return <code>None</code> to start returning <code>Result&lt;T, LassoError&gt;</code> with a variant for <code>OutOfMemory</code> and <code>OutOfKey</code>. That's in my opinion a more elegant solution since the user always has control, but panicking when the limit is met could also be an option, albeit a bad one. As for handling said OOM errors, that's largely up to the user of the library, if there's enough need for it then some method of inspecting the interner and removing unneeded strings could probably be implemented to allow for users to cull whatever strings they don't want</p>
<p>Sorry I took so long to respond, notifications weren't showing up for me</p>



<a name="205024121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Internment%20memory%20limit/near/205024121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Internment.20memory.20limit.html#205024121">(Jul 25 2020 at 22:19)</a>:</h4>
<p>I think how the error would be handled by rust-analyzer is the most difficult part here. We cannot garbage-collect strings since we don't know which ones are still referenced, so that limits our options for handling allocation failure due to the limit too. I think we'd have to delete the entire database, since we don't know which queries contain <code>Name</code>s, at least not in a way that can be machine-checked.</p>
<p>Perhaps rust-analyzer would work better with reference-counted interned strings such as those provided by Servo's <code>string_cache</code> crate. I briefly tried that out in <a href="https://github.com/rust-analyzer/rust-analyzer/pull/5411">https://github.com/rust-analyzer/rust-analyzer/pull/5411</a>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>